import java.lang.reflect.Method;

import erepublik.IERepublikService;
import erepublik.impl.ERepublicServiceImpl;

public class ERepublik {

	public static void main(String[] args) throws Exception {
		if(args.length < 1 || "-help".equals(args[0])) {
			printUsage();
			return;
		}
		
		Class<?>[] parameterTypes = new Class<?>[args.length-1];
		Object[] methodArgs = new Object[args.length-1];
		for(int i=1; i<args.length; i++) {
			try {
				methodArgs[i-1] = (int)Integer.parseInt(args[i]);
				parameterTypes[i-1] = int.class;
			} catch(NumberFormatException e) {
				methodArgs[i-1] = args[i];
				parameterTypes[i-1] = String.class;
			}
		}
		Method m = IERepublikService.class.getMethod(args[0], parameterTypes);
		
		IERepublikService eRepublik = ERepublicServiceImpl.getInstance();
		Object o = m.invoke(eRepublik, methodArgs);
		System.out.println(o.toString());
	}
	
	private static void printUsage() {
		System.err.println("Usage: java [-options ...] ERepublik method <parameters>");
		System.err.println("Options:");
		System.err.println("  -help: display this usage message");
	}

}
